﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using Workbench.Operations;
using Workbench.Shared;

namespace Workbench.Presentation
{
    public class MainWindowViewModel : ViewModelBase
    { 
        private int windowWidth;
        public int WindowWidth
        {
            get
            {
                return windowWidth;
            }
            set
            {
                windowWidth = value;
                UserSettings.WindowWidth = windowWidth;
                RaisePropertyChanged();
            }
        }
        private int windowHeight;
        public int WindowHeight
        {
            get { return windowHeight; }
            set 
            { 
                windowHeight = value;
                UserSettings.WindowHeight = windowHeight;
                RaisePropertyChanged(); 
            }
        }

        private ApplicationMenuViewModel appMenuViewModel;
        public ApplicationMenuViewModel AppMenuViewModel
        {
            get { return appMenuViewModel; }
            set { appMenuViewModel = value; RaisePropertyChanged(); }
        }

        private ProjectViewModel projectViewModel;
        public ProjectViewModel ProjectViewModel
        {
            get { return projectViewModel; }
            set { projectViewModel = value; RaisePropertyChanged(); }
        }

        private WordListViewModel wordListViewModel;
        public WordListViewModel WordListViewModel
        {
            get { return wordListViewModel; }
            set { wordListViewModel = value; RaisePropertyChanged(); }
        }

        private LemmatizerViewModel lemmatizerViewModel;
        public LemmatizerViewModel LemmatizerListViewModel
        {
            get { return lemmatizerViewModel; }
            set { lemmatizerViewModel = value; RaisePropertyChanged(); }
        }

        private POSTaggerViewModel posTaggerViewModel;
        public POSTaggerViewModel POSTaggerViewModel
        {
            get { return posTaggerViewModel; }
            set { posTaggerViewModel = value; RaisePropertyChanged(); }
        }

        private ConcordancerViewModel concordancerViewModel;
        public ConcordancerViewModel ConcordancerViewModel
        {
            get { return concordancerViewModel; }
            set { concordancerViewModel = value; RaisePropertyChanged(); }
        }

        private ExercisesViewModel exercisesViewModel;
        public ExercisesViewModel ExercisesViewModel
        {
            get { return exercisesViewModel; }
            set { exercisesViewModel = value; RaisePropertyChanged(); }
        }


        private bool hasProjectOpened;
        public bool HasProjectOpened
        {
            get { return hasProjectOpened; }
            set { hasProjectOpened = value; RaisePropertyChanged(); }
        }

        private ObservableCollection<TabViewModelBase> tabs = new ObservableCollection<TabViewModelBase>();
        public ObservableCollection<TabViewModelBase> Tabs
        {
            get { return tabs; }
        }

        public MainWindowViewModel()
        {
            WindowWidth = UserSettings.WindowWidth;
            WindowHeight = UserSettings.WindowHeight;

            AppMenuViewModel = new ApplicationMenuViewModel();
            AppMenuViewModel.PropertyChanged += AppMenuViewModel_PropertyChanged;

            WordListViewModel = new WordListViewModel();

            LemmatizerListViewModel = new LemmatizerViewModel();
            POSTaggerViewModel = new POSTaggerViewModel();

            ConcordancerViewModel = new ConcordancerViewModel();

            ExercisesViewModel = new ExercisesViewModel();

            ProjectViewModel = new ProjectViewModel();
            ProjectViewModel.IsSelected = true;

            Tabs.Add(ProjectViewModel);
            Tabs.Add(WordListViewModel);
            Tabs.Add(LemmatizerListViewModel);
            Tabs.Add(POSTaggerViewModel);
            Tabs.Add(ConcordancerViewModel);
            Tabs.Add(ExercisesViewModel);
        }

        void AppMenuViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "CanCloseProject":
                    HasProjectOpened = (sender as ApplicationMenuViewModel).CanCloseProject;
                    Tabs.ForEach(x => x.IsEnabled = HasProjectOpened);
                    break;
            }
        }
    }
}
